#include<bits/stdc++.h>

using namespace std;

int counta[1000000];
int main() {
    memset(counta, 0, sizeof(counta));
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i ++) {
        int l, r;
        cin >> l >> r;
        counta[l] ++;
        counta[r + 1] --;
    }
    for(int i = 1; i <= n; i ++) {
    	counta[i] += counta[i - 1];
	}
    sort(counta + 1, counta + n + 1, less<int>());
    long long sum = 0;
    for(int i = n; i > 0; i --) {
        sum += (i) * counta[i];
    }
    cout << sum << endl;
    return 0;
}
